package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpSaleType;
import com.nuoniu.sibanyun.service.erp.IErpSaleTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/erp/saleType")
@Api(value = "销售类型管理", tags = "销售类型管理")
public class ErpSaleTypeController extends BaseController {

    @Autowired
    private IErpSaleTypeService saleTypeService;

    @GetMapping("pageList")
    @ApiOperation("获取销售类型列表")
    public HttpResult pageList(Page page, ErpSaleType erpSaleType) {
        return HttpResult.ok(saleTypeService.pageList(page, erpSaleType));
    }

    @PostMapping("save")
    @ApiOperation("保存")
    public HttpResult save(@RequestBody ErpSaleType erpSaleType) {
        if(StringUtils.isBlank(erpSaleType.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }
        if(StringUtils.isBlank(erpSaleType.getName())) {
            throw new NuoNiuException("名称不能为空");
        }
//        if(erpSaleType.getStyleId() == null) {
//            throw new NuoNiuException("请选择类型");
//        }

        saleTypeService.saveSaleType(erpSaleType);
        return HttpResult.ok();
    }

    @PostMapping("delete")
    @ApiOperation("删除")
    public HttpResult delete(@RequestBody List<Long> ids) {
        saleTypeService.deleteById(ids);
        return HttpResult.ok();
    }
}
